<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itheima" uri="http://itheima.com/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>商城后台管理</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
	
	<style>
	img{
	width:40px;
	height:40px;
	}
	.table th{
	text-align:center;
	vertical-align:middle!important;
	}
	.table td{
	text-align:center;
	vertical-align:middle!important;
	}
	</style>
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>customer/list.action">商城后台管理系统</a>
	</div>
	<!-- 导航栏右侧图标部分 -->
	<ul class="nav navbar-top-links navbar-right">
	    <!-- 邮件通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-envelope fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-messages">
				<li>
				    <a href="#">
						<div>
							<strong>张经理</strong> <span class="pull-right text-muted">
								<em>昨天</em>
							</span>
						</div>
						<div>今天晚上开会，讨论一下下个月工作的事...</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#">
				        <strong>查看全部消息</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul>
		</li>
		<!-- 邮件通知 end -->
		<!-- 任务通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
			    <i class="fa fa-tasks fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-tasks">
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 1</strong> 
								<span class="pull-right text-muted">完成40%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-success"
									role="progressbar" aria-valuenow="40" aria-valuemin="0"
									aria-valuemax="100" style="width: 40%">
									<span class="sr-only">完成40%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 2</strong> 
								<span class="pull-right text-muted">完成20%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-info" role="progressbar"
									aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"
									style="width: 20%">
									<span class="sr-only">完成20%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有任务</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 任务通知 end -->
		<!-- 消息通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-bell fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-alerts">
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-comment fa-fw"></i> 新回复 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-envelope fa-fw"></i> 新消息 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-tasks fa-fw"></i> 新任务 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-upload fa-fw"></i> 服务器重启 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有提醒</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 消息通知 end -->
		<!-- 用户信息和系统设置 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-user fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li><a href="#"><i class="fa fa-user fa-fw"></i>
				               用户：
				    </a>
				</li>
				<li><a href="#"><i class="fa fa-gear fa-fw"></i> 系统设置</a></li>
				<li class="divider"></li>
				<li>
					<a href="${pageContext.request.contextPath }/logout.do">
					<i class="fa fa-sign-out fa-fw"></i>退出登录
					</a>
				</li>
			</ul> 
		</li>
		
	</ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li>
				    <a href="##" class="active">
				      <i class="fa fa-edit fa-fw"></i> 商品管理
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
  
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">商品管理</h1>
			</div>
		</div>
		
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newManagementDialog" onclick="clearManagement()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">商品信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>商品编号</th>
								<th>商品名称</th>
								<th>店铺名称</th>
								<th>商品描述</th>
								<th>商品库存</th>
								<th>商品价格</th>
								<th>效果图示</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${goods }" var="goods">
								<tr>
									<td>${goods.goods_id }</td>
									<td>${goods.name}</td>
									<td>${goods.shop }</td>
									<td>${goods.description}</td>
									<td>${goods.number }</td>
									<td>${goods.sum }</td>
								    <td><img src="${pageContext.request.contextPath}/img/${goods.avator }"/></td>
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#managementEditDialog" onclick= "editManagement(${goods.goods_id})">修改</a>
										<a href="#" class="btn btn-danger btn-xs" onclick="deleteManagement(${goods.goods_id})">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>

</div>
<!-- 创建商品模态框 -->
<div class="modal fade" id="newManagementDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">添加商品信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_management_form">
					<div class="form-group">
						<label for="new_goodsid" class="col-sm-2 control-label">
						    商品编号
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_goodsid" placeholder="商品编号" name="goods_id" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_goodsname" class="col-sm-2 control-label">商品名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_goodsname" placeholder="商品名称" name="name" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_shopid" class="col-sm-2 control-label">店铺名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_shopid" placeholder="店铺ID" name="shop" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_description" class="col-sm-2 control-label">商品描述</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_description" placeholder="商品描述" name="description" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_sum" class="col-sm-2 control-label">商品库存</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_sum" placeholder="商品库存" name="number" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_price" class="col-sm-2 control-label">商品价格</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_price" placeholder="商品价格" name="sum" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_image" class="col-sm-2 control-label">效果图示</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_image" placeholder="效果图示" name="avator" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createManagement()">添加商品</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改商品模态框 -->
<div class="modal fade" id="managementEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改商品信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_management_form">
					<div class="form-group">
						<label for="edit_goodsid" class="col-sm-2 control-label">商品编号</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_goodsid" placeholder="商品编号" name="goods_id" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_goodsname" class="col-sm-2 control-label">商品名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_goodsname" placeholder="商品名称" name="name" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_shopid" class="col-sm-2 control-label">店铺名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_shopid" placeholder="店铺ID" name="shop" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_description" class="col-sm-2 control-label">商品描述</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_description" placeholder="商品描述" name="description" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_sum" class="col-sm-2 control-label">商品库存</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_sum" placeholder="商品库存" name="number" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_price" class="col-sm-2 control-label">商品价格</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_price" placeholder="商品价格" name="sum" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_image" class="col-sm-2 control-label">效果图示</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_image" placeholder="效果图示" name="avator" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateManagement()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建商品窗口中的数据
	function clearManagement() {
	    $("#new_goodsid").val("");
	    $("#new_goodsname").val("")
	    $("#new_shopid").val("")
	    $("#new_description").val("")
	    $("#new_sum").val("");
	    $("#new_price").val("");
	    $("#new_image").val("");
	}
	// 创建商品
	function createManagement() {
	$.post("<%=basePath%>/managementcreate.do",
	$("#new_management_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("商品创建成功！");
	            window.location.reload();
	        }else{
	            alert("商品创建失败！");
	            window.location.reload();
	        }
	    });
	}
	// 通过id获取修改商品信息
	function editManagement(goods_id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>getManagementById.do",
	        data:{"goods_id":goods_id},
	        success:function(data) {
	            $("#edit_goodsid").val(data.goods_id);
	            $("#edit_goodsname").val(data.name);
	            $("#edit_shopid").val(data.shop)
	            $("#edit_description").val(data.description)
	            $("#edit_sum").val(data.number)
	            $("#edit_price").val(data.sum);
	            $("#edit_image").val(data.avator);
	        }
	    });
	}
    // 执行修改商品操作
	function updateManagement() {
		$.post("<%=basePath%>managementupdate.do",$("#edit_management_form").serialize(),function(data){
			if(data =="OK"){
				alert("商品信息更新成功！");
				window.location.reload();
			}else{
				alert("商品信息更新失败！");
				window.location.reload();
			}
		});
	}
	// 删除商品
	function deleteManagement(goods_id) {
	    if(confirm('确实要删除该商品吗?')) {
	$.post("<%=basePath%>/managementdelete.do",{"goods_id":goods_id},
	function(data){
	            if(data =="OK"){
	                alert("商品删除成功！");
	                window.location.reload();
	            }else{
	                alert("删除商品失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
</script>
</body>
</html>